package com.stone.serverless.rpc.loadbalancer;

import com.netflix.loadbalancer.Server;
import com.stone.serverless.registry.domain.ServiceInstance;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * @Description: TODO
 * @Author: MECHREVO
 * @Date: 2022/1/25 14:48
 * @Version: 1.0.0
 */
@Getter
@Setter
public class StoneServer extends Server {
    private MetaInfo metaInfo;

    private ServiceInstance serviceInstance;

    private Map<String, String> metadata;

    public StoneServer(ServiceInstance serviceInstance) {
        super(serviceInstance.getIp(), serviceInstance.getPort());
        this.serviceInstance = serviceInstance;
        this.metaInfo = new MetaInfo() {
            @Override
            public String getAppName() {
                return serviceInstance.getServiceName();
            }

            @Override
            public String getServerGroup() {
                return null;
            }

            @Override
            public String getServiceIdForDiscovery() {
                return null;
            }

            @Override
            public String getInstanceId() {
                return serviceInstance.getInstanceId();
            }
        };
        this.metadata = serviceInstance.getMetadata();
    }
}
